import { createRouter, RouteRecord, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Grid from '../views/Grid.vue'
import Test from '../views/Test.vue'
import Article from '../views/Article.vue'

// load modules routes
// if need children routes in modules, please DO NOT name it *.route.ts
const modules: any = import.meta.glob('../modules/**/*.route.ts', {
  eager: true,
})
let modulesRoutes: RouteRecord[] = []

for (const path in modules) {
  const routes = modules[path].default.getRoutes()
  if (routes.length > 0) {
    modulesRoutes = modulesRoutes.concat(routes)
  }
}

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
    },
    {
      path: '/grid',
      name: 'grid',
      component: Grid,
    },
    {
      path: '/test',
      name: 'test',
      component: Test,
    },
    {
      path: '/article',
      name: 'article',
      component: Article,
    },
    ...modulesRoutes,
  ],
})

export default router
